package com.example.dllo.keepdemo.train.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.example.dllo.keepdemo.R;
import com.example.dllo.keepdemo.tools.VolleySingleton;
import com.example.dllo.keepdemo.train.bean.TrainCourseBean;

/**
 * Created by dllo on 16/1/25.
 */
public class TrainCourseGridViewAdapter extends BaseAdapter {
    private Context context;
    private TrainCourseBean data;

    public TrainCourseGridViewAdapter(Context context, TrainCourseBean data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.getData().getResults().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_gridview_activity_traincourse,parent,false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tvTitle.setText(data.getData().getResults().get(position).getName());
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(viewHolder.imageView,R.mipmap.placeholder41_41,R.mipmap.placeholder41_41);
        VolleySingleton.getImageLoader().get(data.getData().getResults().get(position).getPhoto(),listener,200,200);
        return convertView;
    }

    class ViewHolder {
        private ImageView imageView;
        private TextView tvTitle;
        public ViewHolder(View view) {
            imageView = (ImageView) view.findViewById(R.id.img_item_activity_traincourse);
            tvTitle = (TextView) view.findViewById(R.id.tv_item_activity_traincourse_title);
        }
    }
}
